package com.wt.controller;

import org.springframework.stereotype.Controller;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.http.HttpSession;
import java.util.Map;

/**
 * Created with IDEA
 * Describe:
 * Author:tianji
 * Date:2018/10/16
 * Time:16:46
 */
@Controller
public class LoginController {

    //@RequestMapping(value = "/user/login",method = RequestMethod.POST)
    @PostMapping(value = "/user/login")
    public String login(@RequestParam("userName") String userName,
                        @RequestParam("password") String password,
                        Map<String,Object> map, HttpSession httpSession){
        if(!StringUtils.isEmpty(userName) && "123456".equals(password)){
            //登录表单成功，防止表单重复提交，可以用重定向
            httpSession.setAttribute("user",userName);
            return "redirect:/main.html";
        }
        map.put("message","用户名或密码错误");
        return "login";
    }
}
